#!/usr/bin/perl
use strict;
use modules::encode;
package cslist;

sub cslist {
    my ($dbh,$remote,$input,$csnum) = @_;
    my $sth; my $auth;
    if ($$input[4] eq "") {
	print $remote "$csnum O $$input[0] :Syntax :LIST <#channel>\n";
    }
    else {
	$sth=$dbh->prepare("SELECT auth FROM ninfo WHERE num = '$$input[0]' AND code = '".encode::encode($$input[0])."';");
	$sth->execute;
	$auth = $sth->fetchrow_array;
	if ($auth eq '0') {
	    print $remote "$csnum O $$input[0] :You have to identify yourself with NickServ before using this command.\n";
	}
	else {
	    $sth=$dbh->prepare("SELECT rnick FROM users WHERE rnick = '$auth' AND level > 449 and channel = '$$input[4]';");
	    $sth->execute;
	    my $true = $sth->fetchrow_array;
	    if (!$true) {
		print $remote "$csnum O $$input[0] :Access denied.\n";
	    }
	    else {
		$sth=$dbh->prepare("SELECT rnick,level,aop,avoice FROM users WHERE channel = '$$input[4]' ORDER BY level DESC");
		$sth->execute;
		print $remote "$csnum O $$input[0] :\026Access List FOR\026 \cB$$input[4]\cB\n";
		print $remote "$csnum O $$input[0] :NICK       LEVEL       AOP       AVOICE\n";
		print $remote "$csnum O $$input[0] :---------------------------------------\n";
		while (my @result = $sth->fetchrow_array) {
		    my $calc = length($result[0]);
		    $calc = 9 - $calc;
		    $calc = " " x $calc;
		    print $remote "$csnum O $$input[0] :$result[0] $calc $result[1]        $result[2]       $result[3]\n";
		}
		print $remote "$csnum O $$input[0] :=========================================\n";
	    }
	}
    }



}
1;
